﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PMisuseAn.behaviour.model
{
    [Serializable()]
    public class MitigationReferences
    {
        public List<Transition> transitions;
        public List<Action> actions;
        public List<State> states;

        public MitigationReferences()
        {
            transitions = new List<Transition>();
            actions = new List<Action>();
            states = new List<State>();
        }

        public bool isEmpty
        {
            get
            {
                if (states.Count() == 0 && transitions.Count() == 0 && actions.Count() == 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }            
        }

        public bool isMitigationState(String stateName)
        {
            bool isMitState = false;

            foreach (State s in states)
            {
                if (s.name.Equals(stateName))
                {
                    isMitState = true;
                }
            }
            return isMitState;

        }

        public void addState(State state)
        {
            if (state == null)
                return;
            bool exist = false;
            foreach (State s in states)
            {
                if (state.name.Equals(s.name))
                {
                    exist = true;
                    break;
                }
            }
            if (exist == false)
            {
                states.Add(state);
            }
        }

        public void removeState(State state)
        {
            foreach (State s in states)
            {
                if (state.name.Equals(s.name))
                {
                    states.Remove(s);
                    break;
                }
            }
        }

        public void addAction(Action action)
        {
            bool exist = false;
            foreach (Action a in actions)
            {
                if (action.name.Equals(a.name))
                {
                    exist = true;
                    break;
                }
            }
            if (exist == false)
            {
                actions.Add(action);
            }
        }

        public void removeAction(Action action)
        {
            foreach (Action a in actions)
            {
                if (a.stateName.Equals(a.stateName) && action.name.Equals(a.name))
                {
                    actions.Remove(a);
                    break;
                }
            }
        }

        public void addTransition(Transition trans)
        {
            bool exist = false;
            foreach (Transition t in transitions)
            {
                if (trans.transitionName.Equals(t.transitionName))
                {
                    exist = true;
                    break;
                }
            }
            if (exist == false)
            {
                transitions.Add(trans);
            }
        }

        public void removeTransition(Transition trans)
        {
            foreach (Transition t in transitions)
            {
                if (trans.transitionName.Equals(t.transitionName))
                {
                    transitions.Remove(t);
                    break;
                }
            }
        }

    }
}
